package com.smartstate.ems.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smartstate.ems.entity.*;
import com.smartstate.ems.entity.Role;
import com.smartstate.ems.entity.RolePermission;
import com.smartstate.ems.entity.TokenData;
import com.smartstate.ems.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface RoleMapper extends BaseMapper<Role> {


    @Select("SELECT * FROM `role` where ROLE_NAME = #{roleName}")
    Role getRoleByName(String roleName);


    @Select("SELECT * FROM `role` where id = #{id}")
    Role getByRoleId(String id);

//    @Select("SELECT * FROM `role` where state = 1")
    @Select("SELECT * FROM `role`")
    List<Role> getEnableAll();
    /**
     * 根据用户id查询用户的角色
     */
    Role getRoleByUserId(@Param(value = "userId") String userId);

    List<Role> getRoleByNameAndStatus(String roleName,String roleStatus);

    int addRole(Role role);

    int addRoleAndPermission(@Param("id") String id, @Param("roleId") String roleId, @Param("permissionId") String permissionId, @Param("roleType") String  roleType);

    RolePermission getPermID(@Param("id") String id);

    @Delete("delete  from role_permission  where role_id=#{id}")
    int delRoleAndPerms(@Param("id") String id);

    int delRoleById(@Param("id") String id);

    List<String>  getRolePermByroleIDs(List<String> ids);

    int batchDelRoleAndPerm(List<String>  ids);

    @Select("select  PERM_ID from  role_permission   where  role_id=#{id}")
    List<String>  getPermsByRoleId(String id);

     int delRolesByIDs(List<String> ids);

    int addRoleAndPermissions(List<RolePermission> list);

    int updatePermById(List<RolePermission> list);

    int delByRoleId(String roleId);

    List<User> getUserByRoleIde(@Param("id") String id);


    List<Role>  getRoleLikeName(@Param("roleName") String rolename,@Param("state")String state);

    List<TokenData>  getTokenById(@Param("roleId") String roleId, @Param("tag") String tag);

    int delUserByRoleId(@Param("roleId") String roleId);

    @Update(" update  role  set state=#{state}  where id=#{roleId}")
    int updateStateByID(@Param("roleId") String roleId,@Param("state")String state);
}
